package com.wilson.integration.lease.app.service.impl;

import com.wilson.integration.lease.app.service.ApartmentInfoService;
import com.wilson.integration.lease.common.entity.ViewAppointment;
import com.wilson.integration.lease.common.entity.vo.apartment.ApartmentItemVO;
import com.wilson.integration.lease.common.entity.vo.appointment.AppointmentDetailVO;
import com.wilson.integration.lease.common.entity.vo.appointment.AppointmentItemVO;
import com.wilson.integration.lease.common.mapper.ViewAppointmentMapper;
import com.wilson.integration.lease.app.service.ViewAppointmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wilson
 * @description 针对表【view_appointment(预约看房信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ViewAppointmentServiceImpl extends ServiceImpl<ViewAppointmentMapper, ViewAppointment> implements ViewAppointmentService {

    @Resource
    private ViewAppointmentMapper viewAppointmentMapper;

    @Resource
    private ApartmentInfoService apartmentInfoService;

    @Override
    public List<AppointmentItemVO> listItemByUserId(Long userId) {
        return viewAppointmentMapper.listItemByUserId(userId);
    }

    @Override
    public AppointmentDetailVO getDetailById(Long id) {
        ViewAppointment viewAppointment = viewAppointmentMapper.selectById(id);

        ApartmentItemVO apartmentItemVo = apartmentInfoService.selectApartmentItemVOById(viewAppointment.getApartmentId());

        AppointmentDetailVO agreementDetailVo = new AppointmentDetailVO();
        BeanUtils.copyProperties(viewAppointment, agreementDetailVo);

        agreementDetailVo.setApartmentItemVO(apartmentItemVo);

        return agreementDetailVo;
    }
}




